package com.usian.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.usian.common.dtos.PageResult;
import com.usian.common.dtos.ResponseResult;
import com.usian.model.media.dtos.WmMaterialDto;
import com.usian.wemedia.entity.WmMaterial;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.wemedia.service.IWmMaterialService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 自媒体图文素材信息表 前端控制器
 * </p>
 *
 * @author usian
 * @since 2022-10-04
 */
@RestController
@RequestMapping("/api/v1/material")
@Api(tags = "自媒体图文素材信息表接口")
@CrossOrigin
public class WmMaterialController{

    @Autowired
    private IWmMaterialService wmMaterialService;

    /**
     * 上传文件
     * @param file
     * @return
     */
    @PostMapping("/upload_picture")
    public ResponseResult<String> uploadPic(@RequestParam(name = "multipartFile") MultipartFile file){
        return ResponseResult.ok(wmMaterialService.uploadPic(file));
    }

    /**
     * 条件分页查询素材列表
     */
    @PostMapping("/list")
    public PageResult<WmMaterial> findPage(@RequestBody WmMaterialDto dto){
        PageResult<WmMaterial> result = wmMaterialService.findPage(dto);
        return result;
    }

    /**
     * 收藏素材
     */
    @PutMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable("id") Integer id){
        wmMaterialService.updateCollection(id,true);
        return ResponseResult.ok();
    }

    /**
     * 取消收藏素材
     */
    @PutMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable("id") Integer id){
        wmMaterialService.updateCollection(id,false);
        return ResponseResult.ok();
    }

    /**
     * 删除素材
     */
    @DeleteMapping("/del_picture/{id}")
    public ResponseResult deleteMaterial(@PathVariable("id") Integer id){
        wmMaterialService.deleteMaterial(id);
        return ResponseResult.ok();
    }


}
